from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response  # 导入Response类，用于返回响应数据

# 创建商品的分页器类，继承自PageNumberPagination
class ProductPageNumberPagination(PageNumberPagination):
    # 默认每页显示的记录数
    page_size = 10
    # 指定分页器的查询参数名称
    page_query_param = "page"
    # 指定每页显示的记录数的查询参数名称
    page_size_query_param = "size"
    # 指定最大每页显示的记录数
    max_page_size = 100
    
    def get_paginated_response(self, data):
        return Response({
            'count': self.page.paginator.count,
            'next': self.get_next_link(),
            'previous': self.get_previous_link(),
            'data': data,
        })
    